$(function () {
    //实例化影片简介编辑器
    tinyMCE.init({
        selector: "#movie_movieDesc",
        theme: 'advanced',
        missingMessage: '请输入影片简介',
        language: "zh",
        required: true,
        strict_loading_mode: 1,
    });
    $("#movie_title").validatebox({
        required: true,
        missingMessage: '请输入影片名称',
    });

    $("#movie_genres").combobox({
        url: "/Movie/genreAll?csrfmiddlewaretoken=" + $('input[name="csrfmiddlewaretoken"]').val(),
        method: "GET",
        required: true,
        valueField: "movieGenresId",
        textField: "movieGenresName",
        panelHeight: "auto",
        missingMessage: '请选择影片体裁',
        editable: false,
    });

    $("#movie_movieYear").validatebox({
        required: true,
        missingMessage: '请输入影片上映年份',
    });

    //单击添加按钮
    $("#movieAddButton").click(function () {
        //验证表单
        if (!$("#movieAddForm").form("validate")) {
            $.messager.alert("错误提示", "你输入的信息还有错误！", "warning");
            $(".messager-window").css("z-index", 10000);
        } else {
            $("#movieAddForm").form({
                url: "/Movie/add",
                queryParams: {
                    "csrfmiddlewaretoken": $('input[name="csrfmiddlewaretoken"]').val()
                },
                onSubmit: function () {
                    if ($("#movieAddForm").form("validate")) {
                        $.messager.progress({text: "正在提交数据中..."});
                        return true;
                    } else {
                        return false;
                    }
                },
                success: function (data) {
                    $.messager.progress("close");
                    $.messager.alert("消息", "保存成功！");
                    $(".messager-window").css("z-index", 10000);
                    $("#movieAddForm").form("clear");
                    tinyMCE.editors['movie_movieDesc'].setContent("");
                }
            });
            //提交表单
            $("#movieAddForm").submit();
        }
    });

    //单击清空按钮
    $("#movieClearButton").click(function () {
        $("#movieAddForm").form("clear");
    });
});
